//
//  LHRecommendTourNotesDetailTableViewCell.m
//  Knight_Tour
//
//  Created by 庞魁 on 15-5-20.
//  Copyright (c) 2015年 TouchOne. All rights reserved.
//

#import "LHRecommendTourNotesDetailTableViewCell.h"
#import "UIImageView+WebCache.h"

@interface LHRecommendTourNotesDetailTableViewCell ()

@property (nonatomic, retain) UIImageView *tourNotesPic;
@property (nonatomic, retain) UILabel *detailLabel;
@property (nonatomic, retain) UIImageView *timePic;
@property (nonatomic, retain) UILabel *timeLabel;

@end

@implementation LHRecommendTourNotesDetailTableViewCell


- (void)dealloc
{
    [_tourNotesPic release];
    [_detailLabel release];
    [_timeLabel release];
    [_timePic release];
    [super dealloc];
}

/**
 *  初始化  设置控件
 */
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        // 设置图片
        self.tourNotesPic = [[UIImageView alloc] init];
        
//        _tourNotesPic.backgroundColor = [UIColor colorWithRed:0.101 green:0.506 blue:0.492 alpha:1.000];
        
        [self.contentView addSubview:_tourNotesPic];
        
        [_tourNotesPic release];
        
        // 设置文字label
        self.detailLabel = [[UILabel alloc] init];
        
//        _detailLabel.backgroundColor = [UIColor colorWithRed:0.701 green:0.246 blue:0.068 alpha:1.000];
        
        _detailLabel.numberOfLines = 0;
        
        [_detailLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:17]];
        
        [self.contentView addSubview:_detailLabel];
        
        [_detailLabel release];
        
        // 设置时间图片
        self.timePic = [[UIImageView alloc] init];
        
//        _timePic.backgroundColor = [UIColor colorWithRed:0.096 green:0.450 blue:0.500 alpha:1.000];
        
        _timePic.image = [UIImage imageNamed:@"time"];
        
        [self.contentView addSubview:_timePic];
        
        [_timePic release];
        
        // 设置时间label
        self.timeLabel = [[UILabel alloc] init];

        [self.contentView addSubview:_timeLabel];
        
        [_timeLabel setFont:[UIFont fontWithName:@"Zapfino" size:8]];
        
        [_timeLabel release];
        
        
    }
    
    
    return self;
}
/**
 *  设置控件布局信息
 */
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    _tourNotesPic.frame = CGRectMake(0, 0, self.contentView.frame.size.width, [UIScreen mainScreen].bounds.size.height  / 2 );
    
    CGFloat f = [[self class] heightWithText:_detailLabel.text];
    _detailLabel.frame = CGRectMake(10, _tourNotesPic.frame.size.height + 10, self.contentView.frame.size.width - 20, f);
    
    _timePic.frame = CGRectMake(10, _detailLabel.frame.origin.y + _detailLabel.frame.size.height + 12, 20, 20);
    
    _timeLabel.frame = CGRectMake(_timePic.frame.origin.x + _timePic.frame.size.width + 5, _detailLabel.frame.origin.y + _detailLabel.frame.size.height + 15, 250, 20);
    
}

/**
 *  重写setter方法
 */

- (void)setNotesDetailModel:(LHRecommendTravelNotesDetailModel *)notesDetailModel
{
    if (_notesDetailModel != notesDetailModel) {
        
        [_notesDetailModel release];
        
        _notesDetailModel = [notesDetailModel retain];
        
    }
    
    [_tourNotesPic sd_setImageWithURL:[NSURL URLWithString:notesDetailModel.photo_1600] placeholderImage:[UIImage imageNamed:@"word4"]];
    
    _detailLabel.text = notesDetailModel.text;
    
    _timeLabel.text = notesDetailModel.local_time;
    
    
}

// 文字自适应高度
+ (CGFloat)heightWithText:(NSString *)text
{
    
    // 创建一个字典保存文本属性
    // 保存文本文字大小
    
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"Helvetica-Bold" size:17], NSFontAttributeName, nil];
    
    // 预设一个尺寸, 文本最大不会超过这个尺寸
    CGSize size = CGSizeMake(LHWidth - 40, 1000);
    
    // 根据文本信息获得一个CGRect
    // 参数1:尺寸范围  参数2:文本属性  参数3:按照什么方式获取Rect  参数4:nil
    CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    return rect.size.height;
    
    
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
